package cn.qf;

public class Department {

    static String company = "Baidu";

    String name;

    // 初始化代码块：多用于初始化对象的成员属性
    {
        System.out.println("到初始化代码块了！");

        this.name = "部门名称";
        System.out.println(this.name);
    }

    /*
    static 修饰的类成员只会在类初次被装载进入 JVM 时执行一次。（一过性、一次性）
     */

    // 静态代码块
    static {
        System.out.println("到静态代码块了！");

        // 错误。静态上下文（静态方法、静态代码块）不能引用非静态的成员（属性、方法）
        // this.name = "部门";

        company = "Google";
    }

    public Department(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Department: {" +
                "company='" + company + '\'' +
                " name='" + name + '\'' +
                '}';
    }
}
